<?php
/**
 * Update a user's preference
 *
 * @param integer $userid ID of user
 * @param string $pref Preference to update
 * @param mixed $value Value to assign to preference
 */
function update_preference($userid,$pref,$value)
{
  global $dbi;

  $pref = trim($pref);

  // check to see if the given value is the current setting
  if ($_SESSION['prefs'][$pref] == $value) {
    // if so then just return
    return;
  }

  if (!empty($_SESSION['prefs'][$pref])) {
    // if the preference exists then update
    $update['value'] = $value;
    $dbi->update("user_prefs",$update,"WHERE userid='{$userid}' AND preference='{$pref}'");
    unset($update);
  } else {
    // otherwise insert a new record
    $insert['userid'] = $userid;
    $insert['preference'] = $pref;
    $insert['value'] = $value;
    $dbi->insert("user_prefs",$insert);
    unset($insert);
  }

  // check to see if we have a session
  if (!empty($_SESSION['userid'])) {
    // if we did, then check to see if this is the current user
    if ($_SESSION['userid'] == $userid) {
      $_SESSION['prefs'][$pref] = $value;
    }
  }
}
//----------------------------------------------------------------------------//
//	Send new password via mail
//----------------------------------------------------------------------------//
function mdp_notify($p_userid,$p_pass)
{
    global $dbi;
    $mlg = new ITmail;

    if (!user_exists($p_userid)) {
        return;
    }
    $subject = _MAILSUBJHEAD_.". ".$mlg->reinit_password1;
    $message  = $mlg->reinit_password2._MAILSUBJHEAD_.$mlg->reinit_password3."\n\n";
    $message .= $mlg->reinit_password4.$p_pass."\n\n";
    $message .= $mlg->reinit_password5;
    $message .= "\n\n";
    $message .= _URL_."\n";
    $message .= "\n";
    $message .= _MAILSIGNATURE_;

  // Make sure we have mail class and initialize it
  include_once(_CLASSES_."mail.class.php");
  if (!is_object($mailer)) {
    $mailer = new MAILER();
    $mailer->set("email_from",_EMAIL_);
  }
  $mailer->subject($subject);
  $mailer->to(email($p_userid));
  $mailer->message($message);
  $mailer->send();
  
}
?>